package com.cs.study.homework._0308;

public class Demo6 {

    public static void main(String[] args) {
        new Thread(new Task(1), "T1").start();
        new Thread(new Task(2), "T2").start();
        new Thread(new Task(3), "T3").start();

    }
}

class Task implements Runnable {
    int threadId;
    static int num = 0;

    public Task(int threadId) {
        this.threadId = threadId;
    }

    @Override
    public void run() {
        while (num < 75) {
            synchronized (Task.class) {
                if (num / 5 % 3 + 1 == threadId) {
                    for (int i = 1; i <= 5; i++) {
                        System.out.println(Thread.currentThread().getName() + "-----" + ++num);
                    }
                    Task.class.notifyAll();
                } else {
                    try {
                        Task.class.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
